//
//  ssssssssssssssssViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/30.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ssssssssssssssssViewController.h"

@interface ssssssssssssssssViewController ()<UIWebViewDelegate>
{

     UIWebView *myWebView;

}



@end

@implementation ssssssssssssssssViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, scrWidth(), scrHeight())];
    //    myWebView.delegate = self;
    [self.view addSubview:myWebView];
    myWebView.delegate = self;
    
    NSString *basePath = [[NSBundle mainBundle]bundlePath];
    NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"index.html"];
    myWebView.backgroundColor = [UIColor whiteColor];
    NSURL *url = [NSURL fileURLWithPath:helpHtmlPath];
    //加载本地html文件
    [myWebView loadRequest:[NSURLRequest requestWithURL:url]];
 //   [self.navigationController setNavigationBarHidden:NO animated:NO];
    NSString *jsStr = [NSString stringWithFormat:@"test.initData('%@')",[PublicFunction getConfigWithKey:@"token"]];
    [myWebView stringByEvaluatingJavaScriptFromString:jsStr];
}

- (void)viewDidLoad {
    [super viewDidLoad];
  
    // Do any additional setup after loading the view.
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *jsStrss = [NSString stringWithFormat:@"test.tiaochong()"];
    [myWebView stringByEvaluatingJavaScriptFromString:jsStrss];
    
}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    /**
     
     <!-- 自定义协议与OC进行交互 -->
     
     // 网页上的一个链接，点击这个链接出发以下反应。。。
     
     <a href="protocol:///showMessage"></a>
     <a href="protocol:///dingDan:订单id money:钱">女神</a>
     */
    
    //在此方法中截取下一个请求的URL,通过自定义协议头，截取要执行的方法和参数
    
    if ([request.URL.scheme isEqualToString:@"protocol"]) {
        
        //调用oc的方法做事
        
        //工作中用下面的
        
        NSArray *pathComponents = [request.URL pathComponents];
        
        //获取到方法名的字符串
        
        NSString *methodName = pathComponents[1];
        
        SEL method = NSSelectorFromString(methodName);
        
        if ([self respondsToSelector:method]) {
            
            [self performSelector:method];
        }
//        else {
//            
//            NSArray *dingDan = [request.URL pathComponents];
//            
//            NSString *ding1 = dingDan[1];
//            
//            NSArray *array = [ding1 componentsSeparatedByString:@"money:"];
//            NSArray *arrOfID = [array[0] componentsSeparatedByString:@"dingDan:"];
//            
//            NSArray *arrID = [arrOfID[1] componentsSeparatedByString:@","];
//            
//            NSLog(@"111111111111111%@", arrOfID[0]);
//            [self dingDan:arrID[0] money:array[1]];
//            
//        }
        return NO;
        
    }
    
    
    return YES;
    
}

// OC的方法

- (void)showMessage{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
